package com.ruoyi.web.controller.quality;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.quality.domain.vo.QualityInternalLossesVo;
import com.ruoyi.quality.domain.bo.QualityInternalLossesBo;
import com.ruoyi.quality.service.IQualityInternalLossesService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 质量内部损失
 *
 * @author ruoyi
 * @date 2023-08-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/quality/internalLosses")
public class QualityInternalLossesController extends BaseController {

    private final IQualityInternalLossesService iQualityInternalLossesService;

    /**
     * 查询质量内部损失列表
     */
    @SaCheckPermission("quality:internalLosses:list")
    @GetMapping("/list")
    public TableDataInfo<QualityInternalLossesVo> list(QualityInternalLossesBo bo, PageQuery pageQuery) {
        return iQualityInternalLossesService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出质量内部损失列表
     */
    @SaCheckPermission("quality:internalLosses:export")
    @Log(title = "质量内部损失", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(QualityInternalLossesBo bo, HttpServletResponse response) {
        List<QualityInternalLossesVo> list = iQualityInternalLossesService.queryList(bo);
        ExcelUtil.exportExcel(list, "质量内部损失", QualityInternalLossesVo.class, response);
    }

    /**
     * 获取质量内部损失详细信息
     *
     * @param lossesId 主键
     */
    @SaCheckPermission("quality:internalLosses:query")
    @GetMapping("/{lossesId}")
    public R<QualityInternalLossesVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long lossesId) {
        return R.ok(iQualityInternalLossesService.queryById(lossesId));
    }

    /**
     * 新增质量内部损失
     */
    @SaCheckPermission("quality:internalLosses:add")
    @Log(title = "质量内部损失", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody QualityInternalLossesBo bo) {
        return toAjax(iQualityInternalLossesService.insertByBo(bo));
    }

    /**
     * 修改质量内部损失
     */
    @SaCheckPermission("quality:internalLosses:edit")
    @Log(title = "质量内部损失", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody QualityInternalLossesBo bo) {
        return toAjax(iQualityInternalLossesService.updateByBo(bo));
    }

    /**
     * 删除质量内部损失
     *
     * @param lossesIds 主键串
     */
    @SaCheckPermission("quality:internalLosses:remove")
    @Log(title = "质量内部损失", businessType = BusinessType.DELETE)
    @DeleteMapping("/{lossesIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] lossesIds) {
        return toAjax(iQualityInternalLossesService.deleteWithValidByIds(Arrays.asList(lossesIds), true));
    }
}
